# glob --- Unix 风格路径名模式扩展
import glob

print(glob.glob('[0-9].*'))  # ['1.tst']
print(glob.glob('*.txt'))  # ['foo.txt']
print(glob.glob('?.txt'))  # []
print(glob.glob('**/*.txt', recursive=True))  # ['foo.txt']
print(glob.glob('c*'))  # ['catalogue.md', 'collections-test.py', 'const.py']

# fnmatch --- Unix 文件名模式匹配
import fnmatch
import os
import re

for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*.txt'):
        print(file)  # ['catalogue.md', 'collections-test.py', 'configparser', 'const.py', 'csv']

print(fnmatch.filter(os.listdir('.'), '*.txt'))  # []

regex = fnmatch.translate('*.txt')
print(regex)  # (?s:.*\.txt)\Z
print(re.match(regex, 'foo.txt'))  # <_sre.SRE_Match object; span=(0, 7), match='foo.txt'>

# linecache
import linecache

print(linecache.__file__)  # D:\SourceCode\original_tools\venv\lib\linecache.py
print(linecache.getline(linecache.__file__, 8))  # import functools
